package com.example;

import cn.hutool.system.*;
import cn.hutool.system.oshi.CpuInfo;
import cn.hutool.system.oshi.OshiUtil;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import oshi.hardware.ComputerSystem;
import oshi.hardware.GlobalMemory;

@SpringBootTest
public class GetSystemInfoTest {

    @Test
    public void test() {
        // Java Virtual Machine Specification信息
        JvmSpecInfo jvmSpecInfo = SystemUtil.getJvmSpecInfo();
        System.out.println("Java Virtual Machine Specification信息: ");
        System.out.println(jvmSpecInfo);

        // Java Virtual Machine Implementation信息
        JvmInfo jvmInfo = SystemUtil.getJvmInfo();
        System.out.println(jvmInfo);

        // Java Specification信息
        JavaSpecInfo javaSpecInfo = SystemUtil.getJavaSpecInfo();
        System.out.println(javaSpecInfo);

        // Java Implementation信息
        JavaInfo javaInfo = SystemUtil.getJavaInfo();
        System.out.println(javaInfo);

        // 获取系统信息
        OsInfo osInfo = SystemUtil.getOsInfo();
        System.out.println(osInfo);

        // 用户信息
        UserInfo userInfo = SystemUtil.getUserInfo();
        System.out.println(userInfo);

        // 当前主机网络地址信息
        HostInfo hostInfo = SystemUtil.getHostInfo();
        System.out.println(hostInfo);

        // 运行时信息，包括内存总大小、已用大小、可用大小等
        RuntimeInfo runtimeInfo = SystemUtil.getRuntimeInfo();
        System.out.println(runtimeInfo);

        // Java运行时信息
        JavaRuntimeInfo javaRuntimeInfo = SystemUtil.getJavaRuntimeInfo();
        System.out.println(javaRuntimeInfo);

        // 综合打印，上面的组合打印
        System.out.println("测试");
        SystemUtil.dumpSystemInfo();


        // 需要引入 oshi-core 依赖
        // ------------ Oshi是Java的免费基于JNA的操作系统和硬件信息库
        CpuInfo cpuInfo = OshiUtil.getCpuInfo();
        Integer cpuNum = cpuInfo.getCpuNum();
        System.out.println("cpuNum: " + cpuNum);
        double used = cpuInfo.getUsed();
        System.out.println("used: " + used);
        System.out.println(cpuInfo);

        // 获取内存总量
        GlobalMemory memory = OshiUtil.getMemory();
        long total = memory.getTotal() / 1024 / 1024 / 1024;
        System.out.println("内存总量：" + total);

        ComputerSystem system = OshiUtil.getSystem();
        System.out.println(system);

        // 获取磁盘信息
        OshiUtil.getHardware().getDiskStores().forEach(System.out::println);
    }
}
